<?php
/* 
 * ebiz front
 * 
 * ProductView
 * 
 * @author allen
 * 
 */

//require_once '../app/views/BaseView.php';
require_once '../app/util/TemplateReplaceUtil.php';
require_once '../app/util/TagUtil.php';
require_once '../app/views/HeaderView.php';
require_once '../app/views/FooterView.php';
require_once '../app/services/ProductService.php';
require_once '../app/util/CommonUtil.php';
require_once '../app/services/VoteService.php';
require_once '../app/services/AAService.php';

require_once "../".$GLOBALS['local']."/product.php";

class ProductView {
	
	private $categoryId = 21;
	private $consultPage = 5;//咨询每页显示条数

	public function render($productUrlTitle, $productinfo, $productItemInfo, $result){
		//判断当前是否为手机种类
		$arrCategory = $result["arr_category"];
		$isMobile = self::judgeIsMobile($arrCategory);
		//get user id
		$userId = 0;
		if(AAService::isLogin()){
			$userId = AAService::getCustomer();
		}
		//$mainContent = self::getProductView($productUrlTitle, $productinfo, $productItemInfo);
		$config = $GLOBALS["config"];
        $productService = new ProductService();
        //get the json data in page
        $json = $productService->getProductJson($productUrlTitle, $isMobile);
        $productTemplate = "";
        $productTemplate .= " \n <script type='text/javascript'> \n ";
        $productTemplate .= " //<![CDATA[ \n";
        $productTemplate .= "   productData = ".$json."; \n";
//        $productTemplate .= "   $(function() {    $('#magnifyImage').magnify();}); \n";
//        $productTemplate .= "\n alert(productData.item_1.attribute_1); ";
        $productTemplate .= "\n //]]> ";
        $productTemplate .= " \n </script> \n ";
		$scpPath = "layout/product.scp";     //replace .scp file layout
        $datascp = TemplateReplaceUtil::getTemplate($scpPath);
        $arr = array();
        $arr =  TemplateReplaceUtil::getXmlParam($datascp);     //return the param in the array
        $itemInfoComponent = isset($arr["item_info"]["name"]) ? $arr["item_info"]["name"] : "item_info_component";
        $itemSummaryComponent = isset($arr["item_summary"]["name"]) ? $arr["item_summary"]["name"] : "item_summary_component";
        $relateProductComponent = isset($arr["relate_product"]["name"]) ? $arr["relate_product"]["name"] : "relate_product_component";
        $navigateHtml = self::getNavigateLayout($result);
        $itemInfoHtml = self::getItemInfoLayout($itemInfoComponent, $productUrlTitle, $productinfo, $productItemInfo, $result);
        $itemPartHtml = self::getItemPartLayout();
        $itemSummaryHtml = self::getItemSummaryLayout($itemSummaryComponent, $result, $productinfo, $productItemInfo);
//        $itemOpinion = "";
        $itemOpinion = self::getItemOpinionLayout($result);
        $itemConsult = self::getItemConsultLayout($result);
        $itemRelateProductHtml = self::getRelateProductLayout($relateProductComponent, $productinfo);
        //generate the big item image when click the item image 
        $itemBigImg = self::getItemBigImg($productItemInfo);
        //replace the layout
        $sclPath = "layout/product.scl";  //replace .scl file layout
        $datascl = TemplateReplaceUtil::getTemplate($sclPath);
//        $datascl = TemplateReplaceUtil::replaceTemplate("<header_content/>", $headerView, $datascl);
//        $datascl = TemplateReplaceUtil::replaceTemplate("<javascript_file/>", "", $datascl);
//        $datascl = TemplateReplaceUtil::replaceTemplate("<css_file/>", "", $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<navigate/>", $navigateHtml, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<item_info/>", $itemInfoHtml, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<item_part/>", $itemPartHtml, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<item_summary/>", $itemSummaryHtml, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<item_opinion/>", $itemOpinion, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<item_consult/>", $itemConsult, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<relate_product/>", $itemRelateProductHtml, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<item_big_img/>", $itemBigImg, $datascl);
//        $datascl = TemplateReplaceUtil::replaceTemplate("<footer_content/>", $footerView, $datascl);
        $mainContent = "";
        $mainContent .= "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> \n ";
        $mainContent .= "<html xmlns='http://www.w3.org/1999/xhtml'> \n ";
        $mainContent .= "<head> \n ";
        $mainContent .= "<meta content='text/html; charset=utf-8' http-equiv='Content-Type' /> \n ";
        $mainContent .= "<title>".$result["product_title"]." - 阿基米米网上商城</title> \n ";
        $mainContent .= "<script type='text/javascript' language='javascript' src='//".ConfigConstants::$iConstants.".".DOMAIN."/n/javascript/lib/jquery.js'></script> \n ";
        $mainContent .= "<script type='text/javascript' language='javascript' src='//".ConfigConstants::$iConstants.".".DOMAIN."/n/javascript/lib/jquery.magnify-1.0.2.js'></script> \n ";
        $mainContent .= "<script type='text/javascript' language='javascript' src='//".ConfigConstants::$iConstants.".".DOMAIN."/n/javascript/frontend.js'></script> \n ";
        $mainContent .= "<script type='text/javascript' language='javascript' src='//".ConfigConstants::$iConstants.".".DOMAIN."/n/javascript/lib/jquery.scrollto.pack.js'></script> \n";
        $mainContent .= "<script type='text/javascript' language='javascript' src='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/javascript/product.js'></script> \n ";
        $mainContent .= "<script type='text/javascript' language='javascript' src='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/javascript/showbigimg.js'></script> \n ";
        $mainContent .= "<script type='text/javascript' language='javascript' src='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/javascript/productTemplate.js'></script> \n ";
        $mainContent .= "<script type='text/javascript' language='javascript' src='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/javascript/akimimi.js'></script> \n ";
        $mainContent .= "<script type='text/javascript' language='javascript' src='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/javascript/showListImg.js'></script> \n ";
//        $mainContent .= "<link href='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/css/style.css' rel='stylesheet' type='text/css' /> \n ";
        $mainContent .= "<link href='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/css/product.css' rel='stylesheet' type='text/css' /> \n ";
        $mainContent .= "<link href='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/css/showimg.css' rel='stylesheet' type='text/css' /> \n ";
        $mainContent .= "<link href='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/css/headerAndFooter.css' rel='stylesheet' type='text/css' /> \n ";
        $mainContent .= "<link href='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/css/default.css' rel='stylesheet' type='text/css' /> \n ";
        $mainContent .= "<link href='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/css/buyKnowledge.css' rel='stylesheet' type='text/css' /> \n ";
        $mainContent .= "<link href='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/css/helpservice.css' rel='stylesheet' type='text/css' /> \n ";
        
        //集成百分点功能 
//        $mainContent .= "<script type='text/javascript' language='javascript' src='".ConfigConstants::getTLayoutPath()."/javascript/bfd/bfd.js'></script> \n ";
//        $mainContent .= "<link href='".ConfigConstants::getTLayoutPath()."/css/bfd/bfd.css' rel='stylesheet' type='text/css' /> \n ";
        
        $mainContent .= $productTemplate;
        
        $mainContent .= "
        <script type='text/javascript'>
            //<![CDATA[
            $(document).ready(function(){
                $('#starPointBox').focus();
                window.location='#';
                });
            //]]>
        </script> \n ";
        //window.href='#top';
        $mainContent .= "</head>";
        $mainContent .= "<body>";
//        $mainContent .= "<div id='recBanner' class='recBanner'></div>";
        $mainContent .= $result["header_view"];
        $mainContent .= $datascl;
        $mainContent .= "<input type='hidden' id='userid' value='". $userId ."' />";
        $mainContent .= $result["footer_view"];
        $mainContent .= self::promptInfo();
        $mainContent .= "</body>";
        $mainContent .= "</html>";
        return $mainContent;
	}
	
	private function getNavigateLayout($result){
		$html = "<div id=\"bq\"><div id=\"top_label\"><img src=\"".ConfigConstants::getTImagePath()."/top.gif\" border=0 style=\"display:none\"/></div></div>";
		$html .= "<div id='navigation'><a href='/'>首页</a>"; 
		$arr_category = $result["arr_category"];
		
	    for ( $i = 0; $i < count($arr_category); $i++ ) {
	    	if( $i == 0 ){
	    		$html .= "<span> &gt; </span><a href='/c/index/".$arr_category[$i]["categoryUrlTitle"]."'>".$arr_category[$i]["short_name"]."</a>";
	    	}elseif( $i == ( count($arr_category) - 1 ) ){
	    		$html .= "<span> &gt; </span><a href='/c/search/".$arr_category[$i]["category_id"]."'>".$arr_category[$i]["short_name"]."</a>";
	    	}else{
	    		$html .= "<span> &gt; </span>".$arr_category[$i]["short_name"];
	    	}
	    	
	    }
	    $html .= "<span> &gt; </span>".$result["product_title"];
	    $html .= "</div>";
//		$html = "<div id='navigation'><a href='/'>首页</a><span> &gt; </span> 手机配件 <span> &gt; </span> 手机 <span> &gt; </span> 三星 <span> &gt; </span> 三星 SCH-W750</div>";
		return $html;
	}
	
	private function getItemInfoLayout($itemInfoComponent, $productUrlTitle, $productinfo, $productItemInfo, $result){
        $html = "";
        $html .= "<div id='product_attribute'>";
        $html .= "<form id='productForm' action='/o/addToShoppingCart' method='post'>";
        $html .= self::getItemInfoComponent($itemInfoComponent, $productUrlTitle, $productinfo, $productItemInfo, $result);
        $html .= "</form>";
        $html .= "</div>";
        return $html;
	}
	
	private function getItemPartLayout(){
		$html = "<div id='pro_combinability'>
    <div class='com_title'>
        <div class='com_left_title'>
            <ul>
                <li class='nav_1'>全部(<span id='allComNum'>0</span>)</li>
                <li class='nav_p'></li>
                <li class='nav_2'>存储卡(21)</li>
                <li class='nav_p'></li>
                <li class='nav_2'>读卡器(5)</li>
                <li class='nav_p'></li>
                <li class='nav_2'>蓝牙耳机(11)</li>
                <li class='nav_p'></li>
                <li class='nav_2'>手机套(21)</li>
            </ul>
        </div>
        <div class='com_right_title'>
            <p><a href='#'>查看已选套餐(0)</a></p>
            <p><a href='#'>套餐须知</a></p>
        </div>
    </div>
    <div class='combo_border'>
        <div class='combo_left'>
            <div  class='combo_img_border'>
                <img src='".ConfigConstants::getTImagePath()."/product_017.gif' alt=''/>
            </div>
            <div class='combo_label'><img src='".ConfigConstants::getTImagePath()."/product_016.gif' alt='' /></div>
        </div>
        <!--右侧滚动开始-->
        <div class='combo_right'>
          <div class='combor_soll_width' id='soll_content'>
          </div>                                              
        </div>        
         <!--右侧滚动结束-->
    </div>    
</div>";
//        return $html; 
	}
	
	private function getItemSummaryLayout($itemSummaryComponent, $result, $productinfo, $productItemInfo){
		$html = "";
		$html .= "<div id='pro_depict'>
  <div class='depict_title'>
     <ul>
        <li class='nav_1'>详细参数</li>
        <li class='nav_p'></li>
        <li class='nav_2'>购买常识</li>
        <!--<li class='nav_2'>价格走势</li>-->
     </ul>
  </div>";
		$html .= self::getItemSummaryComponent($itemSummaryComponent, $result, $productinfo, $productItemInfo);
		$html .= "</div>";
        return $html; 
	}
	
	private function getItemOpinionLayout($result){
		$pid = $result["product_id"];
		$itemIdStrings = $result["product_item_ids"];
		$voteService = new VoteService();
		//得到该商品评价的用户人数和总的评价数目
//        $opinionItemNumber = $voteService->getCommentsNumberByProductId($pid);
        $opinionItemNumber = $voteService->getOpinionNumber($pid);
        $opinionUserNumber = $voteService->getCommentsUserNumberByProductId($pid);
        $opinionItemNumberString = number_format($voteService->getCommentsNumberByProductId($pid));
        $opinionUserNumberString = number_format($voteService->getCommentsUserNumberByProductId($pid));
//		$dealCommon = $voteService->getStarPointForm($pid);
		$dealCommon = $voteService->getFirstPointForm($pid, $itemIdStrings);
		$avgPoint = $voteService->getAvgStarPointView($pid);
		//$dealForm = "";
		$html = "<div id='pro_pingjia'>
    <div class='pingjia_title'>
        <div class='pj_left_title'>
            <ul>
                <li class='nav_1'>交易评价</li>
                <!--<li class='nav_p'></li>-->
                <!--<li class='nav_2'>使用心得</li>-->
            </ul>
        </div> 
        
    </div>

    <div class='comment' id='avgPoint' style='height:auto;'>
    
            <div class='pj_body_title'>";
		
		if($opinionItemNumber > 0 && $opinionUserNumber > 0){
            $html .=" 
                <p>
                <span>{$opinionUserNumberString}</span>
                个用户发表交易评价 查看
                <span style='cursor:pointer;' onclick='window.location=\"/u/showallopinion?pid={$pid}\"'>{$opinionItemNumber}</span>
                条交易评价
                </p>";
		}else{
			$html .="还没有用户对该商品进行评价";
		}
		
		$html .= " 
            </div>
 
        <!--<div id='commentButton' class='title_1' style='margin-left:450px;' onclick='javascript:ProductContent.showComment();'>我来评价</div>-->
        $avgPoint
    </div>
    <div class='pingjia_body'>
        <div id='pingjia_1'>
            <div class='pj_border'>
                <div class='pj_right' id='pjContent'>
                
                    $dealCommon
                    
                </div>
            </div> 
        </div> 
    </div>
</div>";
        return $html;
	}
	
	private function getItemConsultLayout($result){
		$cid = "";
		if(AAService::isLogin()){
			$cid = AAService::getCustomer();
		}
		$pager = new Pager();
		$queryAll = $result["query_all"];
		$queryAllNum = $result["query_all_num"];
		
        $queryGoods = $result["query_goods"];
        $queryGoodsNum = $result["query_doogs_num"];
        $queryDistribute = $result["query_distribute"];
        $queryDistributeNum = $result["query_distribute_num"];
        $queryPayment = $result["query_payment"];
        $queryPaymentNum = $result["query_payment_num"];
        $queryCampuses = $result["query_campuses"];
        $queryCampusesNum = $result["query_campuses_num"];
        $queryMaintain = $result["query_maintain"];
        $queryMaintainNum = $result["query_maintain_num"];
		
		$queryAllHtml = self::generateEachHtml($queryAll, $queryAllNum, $pager, 1);
		$queryGoodsHtml = self::generateEachHtml($queryGoods, $queryGoodsNum, $pager, 2);
		$queryDistributeHtml = self::generateEachHtml($queryDistribute, $queryDistributeNum, $pager, 3);
		$queryPaymentHtml = self::generateEachHtml($queryPayment, $queryPaymentNum, $pager, 4);
		$queryCampusesHtml = self::generateEachHtml($queryCampuses, $queryCampusesNum, $pager, 5);
		$queryMaintainHtml = self::generateEachHtml($queryMaintain, $queryMaintainNum, $pager, 6);
		
		$html = "<div id='pro_advisory'>
    <div class='ady_title'>
        <div class='ady_left_title'>
            <ul>
                <li class='nav_1' id='all_num'>全部咨询(<span id='all_num_id'>$queryAllNum</span>)</li>
                <li class='nav_p'></li>
                <li class='nav_2' id='goods_num'>商品咨询(<span id='goods_num_id'>$queryGoodsNum</span>)</li>
                <li class='nav_p'></li>
                <li class='nav_2' id='distribute_num'>物流配送(<span id='distribute_num_id'>$queryDistributeNum</span>)</li>
                <li class='nav_p'></li>
                <li class='nav_2' id='payment_num'>支付方式(<span id='payment_num_id'>$queryPaymentNum</span>)</li>
                <li class='nav_p'></li>
                <li class='nav_2'>高校送货(<span id='campuses_num_id'>$queryCampusesNum</span>)</li>
                <li class='nav_p'></li>
                <li class='nav_2'>保修与发票(<span id='maintain_num_id'>$queryMaintainNum</span>)</li>
            </ul>
        </div>
        <div class='ady_right_title'>
        <!--
            <p><a href='#'>查看所有用户资讯</a></p>
            <p><a href='#'>查看我的咨询</a></p>
        -->
        </div>
    </div>
    <div class='ady_ts'>关于商品价格、手机版本批次、网站活动的留言回复是有时效的，仅对回复后的一段时间内有效，有可能改变，之前的回复仅供参考。</div>
    <div class='ady_hight' id='consultAllInfo'>
        
    $queryAllHtml
    $queryGoodsHtml 
    $queryDistributeHtml
    $queryPaymentHtml
    $queryCampusesHtml
    $queryMaintainHtml
     
    </div> 
                           
    <div class='ady_page'>
    
    <form action='/o/submitQuery' method='post'>
            
        <div style='margin-top:20px;'>
            <div style='float:left;'>请选择咨询类型：</div>
            <div style='float:left;margin-left:10px;'>
				<select id='queryType' name='queryType'>
				<option value='1'>商品咨询</option>
				<option value='2'>物流配送</option>
				<option value='3'>支付方式</option>
				<option value='4'>高校送货</option>
				<option value='5'>保修与发票</option>
				</select>
            </div>
            <div class='clear'></div>
        </div>
        <div style='margin-top:20px;'>
            <div style='float:left;'>请填写咨询内容：</div>
            <div style='float:left;margin-left:10px;'><textarea id='queryContent' rows='5' cols='85' name='queryContent'></textarea></div>
            <div class='clear'></div>
        </div>
        <div style='margin-top:20px;margin-left:110px;margin-bottom:20px;'>
            <input type='hidden' id='productId' name='productId' value='" . $result["product_id"] . "' />
            <input type='hidden' id='userId' name='userId' value='" . $cid . "' />
        </div>
         <div style='margin-top:20px;margin-left:110px;margin-bottom:20px;'>
             <input id='querySubmit' type='button' value='提&nbsp;&nbsp;交' name='querySubmit' class='qbutton' onclick='javascript:ProductContent.submitQuery();' />         
         </div>
    </form>
    
      
    </div>               
</div>";
        return $html; 
	}
	
	/**
	 * generate each consult html 
	 */
	private function generateEachHtml($queryAll, $queryAllNum, $pager, $currentDiv){
		//get the page size from config table
//        $itemsPerPage = $GLOBALS["config"]['items_per_page'];//akimimi set is 5
		$pager->setJavascriptFunction("javascript:ProductContent.ajaxPaginate");
        $headerPaginate = $pager->paginate(1, $queryAllNum, "", 5);
        $queryAllHtml = "<div id='ady_" . $currentDiv . "'>";
        foreach ($queryAll as $item) {
            $queryAllHtml .= "<div class='ady_body'>
                                <div class='ady_arraign'>";
            $queryAllHtml .= $item["query_content"];
            $queryAllHtml .= "  </div>
                                <div class='ady_row_1'>  用户名： ";
            $queryAllHtml .= $item["user_name"];
            $queryAllHtml .= "  时间： ";
            $queryAllHtml .= $item["query_created"];
            $queryAllHtml .= "  咨询类型： ";
            $queryAllHtml .= $item["query_type"];
            $queryAllHtml .= "  </div>";
            if( !empty($item["reply_content"]) && !empty($item["reply_modified"]) ){
	            $queryAllHtml .= "  <div class='ady_reply'>";
	            $queryAllHtml .= $item["reply_content"];
	            $queryAllHtml .= "  </div>";
	            $queryAllHtml .= "  <div class='ady_row_2'>";
	//            $queryAllHtml .= $item["admin_name"];
	            $queryAllHtml .= "  回复于   ";
	            $queryAllHtml .= $item["reply_modified"];
	            $queryAllHtml .= "  </div>  ";
            }
            $queryAllHtml .= "</div>  ";
        }
        $queryAllHtml .= "<div class='p2_page'>".$headerPaginate."</div>";
        $queryAllHtml .= "</div>";
        return $queryAllHtml;
	}
	
	private function getRelateProductLayout($relateProductComponent, $productinfo){
		$html = "<div id='pro_tjw'>
    <div class='tjw_title'></div>
    <div class='tjw_top'></div>
    <div class='tjw_body'>";
		for($i = 0; $i < 7; $i++){
			$html .= "<div class='tjw_body_pro'>";
			$html .= self::getRelateProductComponent($relateProductComponent);
	        $html .= "</div>";
		}
		$html .= "    </div>
    <div class='tjw_bottom'></div>
</div>";
        //return $html; 
	}
	
	//generate the component html of item info
	private function getItemInfoComponent($componentName, $productUrlTitle, $productinfo, $productItemInfo, $result){
		$itemImg = self::getItemImg($productItemInfo);
		$itemDesc = self::getItemDescInfo($productItemInfo, $productinfo, $result);
		$customService = self::getCustomOnlineService($result);
		$sccPath = "component/$componentName.scc";
        $datascl = TemplateReplaceUtil::getTemplate($sccPath);
        $datascl = TemplateReplaceUtil::replaceTemplate("<item_img/>", $itemImg, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<item_desc/>", $itemDesc, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<custom_service/>", $customService, $datascl);
        return $datascl;
	}
	
	//generate the component info of item info
	private function getItemImg($productItemInfo){
		$defaultItemId = $productItemInfo['show_itemid'][0];
        //generate default product image  
        $defaultSrc = $productItemInfo["item_".$defaultItemId]['main_image_url'];
        $imageSize = "400.jpg";
        $src = $defaultSrc.$imageSize;
      //show the item images,ex:front backend direction ...
        $srcs = $productItemInfo["item_".$defaultItemId]['image_url'];
//        $picListSize = isset($arr["product_picture_list"]['image_attr']) ? $arr["product_picture_list"]['image_attr'] : "30.png";
        $picListSize = "400.jpg";
		$itemImg = "<div id='img_style'>";
        if( empty($defaultSrc) ){
        	$itemImg .= "<div class='big_img' id='showImg'><img src='" . ConfigConstants::getDefaultProductImagePath(400) . "' alt='" . $src . "' /></div>";
        }else{
        	$itemImg .= "<div class='big_img' id='showImg'><img src='" . $src . "' alt='" . $src . "' /></div>";
        }
		$itemImg .= "<div class='small_border'>
            <div id='prevlabel'></div>  
            <div id='list_img'>
                <div id='rool_list'>";
        if(!empty($srcs)){
            foreach($srcs as $src){
                $itemImg .= " <img src='".$src.$picListSize."' alt='".$src.$picListSize."' />";
            }
        }
        $itemImg .= "</div>
           </div>
          <div id='nextlabel'></div>
        </div>
  </div>";
		return $itemImg;
	}
	
	private function getItemDescInfo($productItemInfo, $productinfo, $result){
		$categoryUrlTitle = $result["category_url_title"];
		$arrCategory = $result["arr_category"];
        $itemBuyKnowledge = ProductService::generateBuyTopPrimaryKnowledgeByCategoryUrlTitle($categoryUrlTitle);
		$shortMetadata = $result["metadata_info"]["short_data"];
		$defaultItemId = $productItemInfo['show_itemid'][0];
        $hProductId = $productItemInfo["item_".$defaultItemId]['product_id'];
        $marketPrice = $productItemInfo["item_".$defaultItemId]['market_price'];
        $listPrice = $productItemInfo["item_".$defaultItemId]['list_price'];
        $salePrice = $productItemInfo["item_".$defaultItemId]['sale_price'];
        
        $itemPrice = self::generateItemPrice($marketPrice, $listPrice, $salePrice);
        $mainMetadataHtml = self::generateMainMetadataHtml($shortMetadata);
        
        $hiddenSalePrice = "<input id='hSalePrice' name='hSalePrice' type='hidden' value='".$salePrice."' />";
        $hiddenProductId = "<input id='hProductItemId' name='hProductItemId' type='hidden' value='".$defaultItemId."' />";
        $hiddenProductItemId = "<input id='hProductId' name='hProductId' type='hidden' value='".$hProductId."' />";
		$productAttrbutes = self::showAttribute($defaultItemId, $productItemInfo, $arrCategory);
        $itemDesc = "<div id='product_parameter'>
        <div class='pro_title' style='height:auto;'>".$productinfo["product"]["title"]."</div>
        
        $itemPrice
        
        <div id='primaryMetadataInfo'>
        $mainMetadataHtml
        </div>
      
        
        $productAttrbutes
        ";
        
        $itemDesc .= "<div class='pro_changshi'>
            <div class='p_row_12'>购物常识</div>
            <div class='p_row_9'>
                $itemBuyKnowledge
            </div> 
            <div class='p_row_13'>
                <p onclick=\"window.location='#'\">全国联保</p>
                <p onclick=\"window.location='#'\">24小时发货</p>
        </div>                     
        </div>
        
        <div class='fenx_border'>       
            <div class='pro_fenxiang' id='p_fx_1' >
                <div class='p_row_10'>
                <a href=\"javascript:void((function(s,d,e){if(/renren\.com/.test(d.location))return;var%20f='http://share.renren.com/share/buttonshare.do?link=',u=d.location,l=d.title,p=[e(u),'&title=',e(l)].join('');function%20a(){if(!window.open([f,p].join(''),'xnshare',['toolbar=0,status=0,resizable=1,width=626,height=436,left=',(s.width-626)/2,',top=',(s.height-436)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent));\">
                    <img src='".ConfigConstants::getTImagePath()."/product_039.gif' alt='' />
                </a>
                </div>
            </div> 
            <div class='pro_fenxiang'>
                <div class='p_row_11'>
                    <a href=\"javascript:void((function(s,d,e){if(/renren\.com/.test(d.location))return;var%20f='http://share.renren.com/share/buttonshare.do?link=',u=d.location,l=d.title,p=[e(u),'&title=',e(l)].join('');function%20a(){if(!window.open([f,p].join(''),'xnshare',['toolbar=0,status=0,resizable=1,width=626,height=436,left=',(s.width-626)/2,',top=',(s.height-436)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent));\">分享到校内网</a>
                </div>
                <!--
                <p></p>
                -->
            </div>
        </div>
        <div class='pro_button'>
            <span><a href='javascript:ProductContent.submitAddToShoppingCart();'><img src='".ConfigConstants::getTImagePath()."/product_009.gif'  alt=''/></a></span>";
            //if(AAService::isLogin()){
                $itemDesc .= "<span><a href='javascript:ProductContent.submitAddToWishlist();'><img src='".ConfigConstants::getTImagePath()."/product_0091.gif'  alt=''/></a></span>";
            //}
            $itemDesc .= "<!--
            <span><a href='#'><img src='".ConfigConstants::getTImagePath()."/product_010.gif'  alt=''/></a></span>
            <span><a href='#'><img src='".ConfigConstants::getTImagePath()."/product_011.gif'  alt=''/></a></span>
            -->
       $hiddenSalePrice $hiddenProductId $hiddenProductItemId
        </div>        
    </div>";
		return $itemDesc;
	}
	
	private function getCustomOnlineService($result){
		$html = "";
		if( !empty($result[0]['campuses_name']) && !empty($result[1]['sale_num']) ){
			$html = "<p>你所在的学校<span>".$result[0]['campuses_name']."</span><br/>此商品已卖出".$result[1]['sale_num']."件</p>";
		}
		$customService = "<div id='attribute_right'>
        <div class='pro_kf_img'>
            <img src='".ConfigConstants::getTImagePath()."/product_012.gif'  alt='' />
            $html
        </div>
         <div class='kf_border'>
            <p>
                
	            <!--
	            <a target='blank' href='http://wpa.qq.com/msgrd?V=\"1\"&quot;Uin=\"1034487347\"&quot;Site=\"阿基米米\"&quot;Menu=\"yes\"'>
	            -->
	            <a target='blank' href='http://wpa.qq.com/msgrd?V=1&Uin=1034487347&Site=阿基米米&Menu=yes'>
	               <img border='0' src='http://wpa.qq.com/pa?p=\"1:1034487347:8\"' align='middle' alt='Akimimi客服' />
	            </a> 
	            <!--
	            <a target='blank' href='http://wpa.qq.com/msgrd?V=\"1\"&quot;Uin=\"864848052\"&quot;Site=\"阿基米米\"&quot;Menu=\"yes\"'>
	            -->
	            <a target='blank' href='http://wpa.qq.com/msgrd?V=1&Uin=864848052&Site=阿基米米&Menu=yes'>
	               <img border='0' src='http://wpa.qq.com/pa?p=\"1:864848052:8\"' align='middle' alt='Akimimi客服' />
	            </a>
            </p>
            <p>
                
                <a target='_blank' href='http://amos1.taobao.com/msg.ww?v=2&uid=%E9%98%BF%E5%9F%BA%E7%B1%B3%E7%B1%B3%E5%AE%A2%E6%88%B7%E6%9C%8D%E5%8A%A1&s=1' >
                   <img border='0' src='http://amos1.taobao.com/online.ww?v=2&uid=%E9%98%BF%E5%9F%BA%E7%B1%B3%E7%B1%B3%E5%AE%A2%E6%88%B7%E6%9C%8D%E5%8A%A1&s=1' alt='Akimimi客户服务' />
                </a>
                <a target='_blank' href='http://amos1.taobao.com/msg.ww?v=2&uid=%E7%B1%B3%E7%B1%B3%E5%AE%A2%E6%88%B7%E6%9C%8D%E5%8A%A1&s=1' >
                   <img border='0' src='http://amos1.taobao.com/online.ww?v=2&uid=%E7%B1%B3%E7%B1%B3%E5%AE%A2%E6%88%B7%E6%9C%8D%E5%8A%A1&s=1' alt='Akimimi客户服务' />
                </a>
                <!--
                <a target='_blank' href='http://amos1.taobao.com/msg.ww?v=\"2\"&quot;uid=\"%E9%98%BF%E5%9F%BA%E7%B1%B3%E7%B1%B3%E5%AE%A2%E6%88%B7%E6%9C%8D%E5%8A%A1\"&quot;s=\"1\"' >
                   <img border='0' src='".ConfigConstants::getTImagePath()."/product_013.gif' alt='Akimimi客户服务' />
                </a>
                -->
            </p>            
            <p>
                
	            <a href='msnim:chat?contact=akimimi@126.com'>
	               <img src='".ConfigConstants::getTImagePath()."/msn.jpg' border='0' alt='点击这里给我发消息' />
	            </a>
            </p>
        </div>
    </div>";
		return $customService;
	}
	
	//click the img to show the big img 
	private function getItemBigImg($productItemInfo){
		$defaultItemId = $productItemInfo['show_itemid'][0];
        //generate default product image  
        $defaultSrc = $productItemInfo["item_".$defaultItemId]['main_image_url'];
        $imageSize = "400.jpg";
        $src = $defaultSrc.$imageSize;
      //show the item images,ex:front backend direction ...
        $srcs = $productItemInfo["item_".$defaultItemId]['image_url'];
//        $picListSize = isset($arr["product_picture_list"]['image_attr']) ? $arr["product_picture_list"]['image_attr'] : "30.png";
        $picListSize = "400.jpg";
		$html ='<div id="bigbody" style="display:none">';
	    $html .='<div id="zxx_test_box">';
	    $html .='<div class="small_img_body">';
	    $html .='<div class="bigprevlabel"></div>';
	    $html .='<div class="big_list_img">';
	    $html .='<div class="pic_small" id="pic_small_area_list">';
        if(!empty($srcs)){
            $i = 0;
            foreach($srcs as $src){
                $html .= ' <a href="#' . $i . '"><img src="'.$src.$picListSize.'" alt="'.$src.$picListSize.'" /></a>';
                $i++;
            }
        }
	    $html .='</div>';
	    $html .='</div>';
	    $html .='<div class="bignextlabel"></div>';
	    $html .='</div>';
	    $html .='<div class="pic_chg_box">';
	    $html .='<ul class="pic_in_area" id="pic_chg_area">';
        if(!empty($srcs)){
            $html .= '<li><img class="myImg" src="'.$srcs[0].$imageSize.'" /></li>';
        }else{
        	$html .= '<li><img class="myImg" src="'.ConfigConstants::getTImagePath()."/product_".$imageSize.'" alt="" /></li>';
        }
	    $html .='</ul>';
	    $html .='</div>';
	    $html .='<div class="close_pic"></div>';  
	    $html .='</div>';   
	    $html .='</div>';
	    return $html;
	}
	
	//在产品描述部分生成每个item的图片
	private function getItemImageDesc($productItemInfo){
		$defaultItemId = $productItemInfo['show_itemid'][0];
        $srcs = $productItemInfo["item_".$defaultItemId]['image_url'];
        $picListSize = "600.jpg";
        $itemImg = "";
        if(!empty($srcs)){
            foreach($srcs as $src){
                $itemImg .= "<div align='center' style='margin-top:10px;margin-bottom:10px;'> <img src='".$src.$picListSize."' alt='".$src.$picListSize."' /></div>";
            }
        }
        return $itemImg;
	}
	
	private function getItemSummaryComponent($componentName, $result, $productinfo, $productItemInfo){
		$productItemImageDesc = self::getItemImageDesc($productItemInfo);
		$metadata = $result["metadata_info"]["data"];
		$productDesc = $productinfo["product"]["description"];
		$categoryUrlTitle = $result["category_url_title"];
		$metadataHtml = self::generateAllMetadataHtml($metadata, $productDesc);
	    
		if(empty($productDesc)){
			$productDesc = "";
		}
            $htmlDesc = "<div class='depict_row_2' style='height:auto; border-bottom:1px solid #DEDEDE; margin-bottom:7px;'>";
            $htmlDesc .= "<ul><li class='style_3' style='height:auto;'>产品描述</li>";
            $htmlDesc .= "<li class='style_2' style='height:auto;'>$productDesc<div id='productItemImageDesc'>$productItemImageDesc</div></li>
                            </ul></div>";
        $itemParam = "<div id='detail_par_1'><!--选项卡一-->
    <div class='depict_row_1'>
        此款产品的详细参数仅供参考，厂家随时有可能修改其中的任何一项参数，若参数没有及时更新，造成差异请以实际出厂的参数为准。
    </div>
    <div id='allMetadataInfo'>
    $metadataHtml
    </div>
    $htmlDesc
    
    
</div>";
    $buyCommon = "<div id='detail_par_3' style='display:none'><!--选项卡二-->
    <div class='depict_row_1'>
                购买常识
    </div>";
    $buyCommon .= ProductService::generateBuyKnowledgeByCategoryUrlTitle($categoryUrlTitle);
    $buyCommon .= "</div>";
        $priceTrend = "<div id='detail_par_2' style='display:none'><!--选项卡三-->
    <div class='depict_row_1'>
        选项卡三
    </div>
    <div class='depict_row_2'>
        <ul>
            <li class='style_3'>基本参数</li>
            <li class='style_2'></li>
        </ul>
    </div>
    <div class='depict_row_2'>
        <ul>
            <li class='style_1'>型号</li>
            <li class='style_2'>S8000C</li>
        </ul>
    </div>  
    <div class='depict_row_2'>
        <ul>
            <li class='style_1'>手机类型</li>
            <li class='style_2'>手写手机,拍照手机</li>
        </ul>
    </div>
    </div>";
        $sccPath = "component/$componentName.scc";
        $datascl = TemplateReplaceUtil::getTemplate($sccPath);
        $datascl = TemplateReplaceUtil::replaceTemplate("<item_param/>", $itemParam, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<buy_common/>", $buyCommon, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<price_trend/>", $priceTrend, $datascl);
        return $datascl;
	}
	
	private function getRelateProductComponent($componentName){
        $relateImg = "<div class='tjw_pro_img'><a href='#'><img src='images/product_035.gif' alt='' /></a></div>";
        $relateTitle = "<p><a href='#'>韩版最爱鱼嘴甜美非夹脚麻坡跟蝴蝶凉鞋</a></p>";
        $relatePrice = "<p class='style_1'>￥<span>159,00</span></p>";
        $sccPath = "component/$componentName.scc";
        $datascl = TemplateReplaceUtil::getTemplate($sccPath);
        $datascl = TemplateReplaceUtil::replaceTemplate("<relate_img/>", $relateImg, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<relate_title/>", $relateTitle, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<relate_price/>", $relatePrice, $datascl);
        return $datascl;
	}
	
	/**
	 * show the item attribute
	 * as select style
	 */
    private function showAttribute($defaultItemId, $productItemInfo, $arrCategory){
    	// [attribute_2] => 重量            [attribute_2_title] => 3米长            [value_2] => 31
        //初始化item的五个属性名称,title和value
    	$attr1 = array();
        $attr1Title = array();
        $attr1ColorPath = array();
        $attr2 = array();
        $attr2Title = array();
        $attr3 = array();
        $attr3Title = array();
        $attr4 = array();
        $attr4Title = array();
        $attr5 = array();
        $attr5Title = array();
        $firstAttrIsColor = false;
        //生成第一个属性的属性title和属性value
        if(!empty($productItemInfo["item_$defaultItemId"]["attribute_1"])){
        	if( trim($productItemInfo["item_$defaultItemId"]["attribute_1_color_path"]) == "" ){//first attribute is not color attribute
	            foreach ($productItemInfo as $key => $item) {
	                if(substr($key, 0, 4) == 'item'){
	                    $attr1[] = $item["value_1"];
                        $attr1Title[] = $item["attribute_1_title"];
	                }
	            }
        	}else{//first is color attribute
        	   $firstAttrIsColor = true;
        	   foreach ($productItemInfo as $key => $item) {
                    if(substr($key, 0, 4) == 'item'){
                        $attr1[] = $item["value_1"];
                        $attr1Title[] = $item["attribute_1_title"];
                        $attr1ColorPath[] = $item["attribute_1_color_path"];
                    }
                }
        	}
        }
        //生成第二个属性的属性title和属性value(根据第一个属性的值生成第二个属性的信息)
        if(!empty($productItemInfo["item_$defaultItemId"]["attribute_2"])){//如果属性存在
            foreach ($productItemInfo as $key => $item) {
                if(substr($key, 0, 4) == 'item'){
                	//根据第一个属性的值过滤第二个属性值  如果是手机分类则不添加第二个属性信息
                	if( $productItemInfo["item_".$defaultItemId]["value_1"] == $item["value_1"] && !self::judgeIsMobile($arrCategory) ){
	                    $attr2[] = $item["value_2"];
	                    $attr2Title[] = $item["attribute_2_title"];
                	}
                }
            }
        }
        //生成第3个属性的属性title和属性value(根据第1个,第2个属性的值生成第二个属性的信息)
        if(!empty($productItemInfo["item_$defaultItemId"]["attribute_3"])){//如果属性存在
            foreach ($productItemInfo as $key => $item) {
                if(substr($key, 0, 4) == 'item'){
                	//根据第1,2个属性的值过滤第3个属性值
                	if( $productItemInfo["item_".$defaultItemId]["value_1"] == $item["value_1"] && $productItemInfo["item_".$defaultItemId]["value_2"] == $item["value_2"] ){
	                    $attr3[] = $item["value_3"];
	                    $attr3Title[] = $item["attribute_3_title"];
                	}
                }
            }
        }
        //生成第4个属性的属性title和属性value(根据第1,2,3个属性的值生成第二个属性的信息)
        if(!empty($productItemInfo["item_$defaultItemId"]["attribute_4"])){//如果属性存在
            foreach ($productItemInfo as $key => $item) {
                if(substr($key, 0, 4) == 'item'){
                	//根据第1,2,3个属性的值过滤第4个属性值
                	if( $productItemInfo["item_".$defaultItemId]["value_1"] == $item["value_1"] && $productItemInfo["item_".$defaultItemId]["value_2"] == $item["value_2"]  && $productItemInfo["item_".$defaultItemId]["value_3"] == $item["value_3"] ){
	                    $attr4[] = $item["value_4"];
	                    $attr4Title[] = $item["attribute_4_title"];
                	}
                }
            }
        }
        //生成第5个属性的属性title和属性value(根据第1,2,3,4个属性的值生成第二个属性的信息)
        if(!empty($productItemInfo["item_$defaultItemId"]["attribute_5"])){//如果属性存在
            foreach ($productItemInfo as $key => $item) {
                if(substr($key, 0, 4) == 'item'){
                	//根据第1,2,3,4个属性的值过滤第5个属性值
                	if( $productItemInfo["item_".$defaultItemId]["value_1"] == $item["value_1"] && $productItemInfo["item_".$defaultItemId]["value_2"] == $item["value_2"] && $productItemInfo["item_".$defaultItemId]["value_3"] == $item["value_3"] && $productItemInfo["item_".$defaultItemId]["value_4"] == $item["value_4"] ){
	                    $attr5[] = $item["value_5"];
	                    $attr5Title[] = $item["attribute_5_title"];
                	}
                }
            }
        }
        
        
        //生成这个产品的所有属性名称  (颜色重量等)
        $attrName = array();
        foreach($productItemInfo as $key => $item){
            if( substr($key, 0, 4) == 'item' ){
            	for ( $i = 1; $i <= 5;$i++ ){
	            	if(!empty($item["attribute_$i"])){
	            		$attrName[] = $item["attribute_$i"];//get all attribute name title(attribute_1,attribute_2, ...)
	            	}
            	}
            }
        }

        $attr1 = array_unique($attr1);
        $attr1Title = array_unique($attr1Title);
        $attr1ColorPath = array_unique($attr1ColorPath);
        $attr2= array_unique($attr2);
        $attr2Title = array_unique($attr2Title);
        if(empty($attr1)){
            return "";
        }
        $firstAttrNum = 1;//default first not color attribute
        if($firstAttrIsColor){
        	$firstAttrNum = 2;//第一个属性显示色块，从第二个属性开始显示下拉列表框
        }
        $otherAttributeResult = array("attr2" => $attr2,
                                      "attr2Title" => $attr2Title,
                                      "attr3" => $attr3,
                                      "attr3Title" => $attr3Title,
                                      "attr4" => $attr4,
                                      "attr4Title" => $attr4Title,
                                      "attr5" => $attr5,
                                      "attr5Title" => $attr5Title
        );
//        print_r($attr2);
//        print_r($attr2Title);exit;
        return self::generateAttributeHtml($firstAttrNum, $productItemInfo, $attr1, $attrName, $attr1Title, $attr1ColorPath, $arrCategory, $otherAttributeResult);
    }

    /**
     * generate the attribute html , exception color attribute
     * $firstAttrNum 1从第一个属性开始生成select   2 是第一个属性是色块  从第二个属性开始生成select
     * $productItemInfo 当前product下所有item信息
     * $attr1 属性1的值  即表中value字段的值，比对产品用此值比对
     * $attrName 产品的所有属性名 比如手机属性名    颜色和移动定制
     * $attr1Title 属性1的title 比如红白 黑白
     * $attr1ColorPath 颜色色块的文件名 比如FFFFFF
     * $arrCategory 为当前产品上级所有category的url title集合    过滤手机时使用
     * $otherAttributeResult 存储其余四个属性信息供初始化页面时产生defaultitem时使用
     */
    private function generateAttributeHtml($firstAttrNum, $productItemInfo, $attr1, $attrName, $attr1Title, $attr1ColorPath="", $arrCategory, $otherAttributeResult){
    	$html = "";
    	$defaultItemId = $productItemInfo['show_itemid'][0];
    	$attrNumber = $productItemInfo["attr_num"];//get the current attribute number (有效的属性个数)
    	
//    	if($firstAttrNum == 1){//first attr is not color attribute
	        
    		$html .= " \n <input id='hSelectLabel' type='hidden' value='".SELECTLABEL."' />";//将select国际化
	        for($i = 1; $i <= $productItemInfo["attr_num"]; $i++){
	            if($i == 1 && $firstAttrNum == 1){//当前是第一个属性并且第一个属性不是颜色属性
	            	$html .= " \n <div class='pro_color'>\n ";
	            	$html .= " \n <div class='p_row_7'> ".$attrName[$i-1]."</div>  \n ";
	            	$html .= " \n <div class='p_row_8'> \n ";
                    $html .= " \n <input type='hidden' id='isColorAttr' value='0' /> \n ";//不是颜色则在IE6下控制第一个属性（下拉列表框）的显示和隐藏
	                $html .= "\n <select id='".$i."' name='attributes' onchange='javascript:changeAttribute(this.value, this.id);'>";
	                $html .= "\n <option value='-1'>".SELECTLABEL."</option>";
	                foreach ($attr1 as $key => $item){
	                	if( $productItemInfo["item_".$defaultItemId]["value_1"] == $item ){
                            $html .= "\n <option value='".$item."' selected='selected'>". $attr1Title[$key] ."</option>";
	                	}else{
                            $html .= "\n <option value='".$item."'>". $attr1Title[$key] ."</option>";
	                	}
                    }
	                $html .= "\n </select>";
	                $html .= "\n </div>";
	                $html .= "\n </div>";
	            }elseif( $i == 1 && $firstAttrNum != 1 ){//当前是第一个属性并且第一个属性是颜色属性生成色块
	            	$html .= " \n <div class='pro_color'> \n ";
                    $html .= " \n <div class='p_row_7'> ".$attrName[$i-1]."</div>  \n ";
                    $html .= " \n <div class='p_row_8'> \n ";
                    $html .= " \n <input type='hidden' id='isColorAttr' value='1' /> \n ";//是颜色则在IE6下不控制第一个属性的显示和隐藏
                    $html .= " \n <input type='hidden' id='1' value='".$attr1[0]."' /> \n ";
                    foreach ($attr1 as $key => $item){//生成色块
                        if( $productItemInfo["item_".$defaultItemId]["value_1"] == $item ){//当前选中的默认产品的颜色
                            $html .= " \n <a href='javascript:void(0);' title='".$attr1Title[$key]."' onclick='javascript:changeAttribute($item, 1);' style='border: 2px solid rgb(161, 210, 21); margin: 3px 4px 0pt 0pt; float: left; height: 13px; width: 13px;'> \n ";
                            $html .= "<img alt='".ConfigConstants::getProductBolbColorPath($attr1ColorPath[$key])."' src='".ConfigConstants::getProductBolbColorPath($attr1ColorPath[$key])."'/></a>";
                            $html .= " \n </a> \n ";
                        }else{
                            $html .= " \n <a href='javascript:void(0);' title='".$attr1Title[$key]."' onclick='javascript:changeAttribute($item, 1);'> \n ";
                            $html .= "<img alt='".ConfigConstants::getProductBolbColorPath($attr1ColorPath[$key])."' src='".ConfigConstants::getProductBolbColorPath($attr1ColorPath[$key])."'/></a>";
                            $html .= " \n </a> \n ";
                        }
                    }
                    $html .= "\n </div>";
                    $html .= "\n </div>";
	            }else{//当前不是第一个属性，根据defaultitemid生成其他默认被选中的属性
//	            	if( $attrNumber != 1 && !self::judgeIsMobile($arrCategory) ){//有效属性不止一个,排除手机,手机只有一个属性色块
	            	if( $attrNumber != 1 ){//有效属性不止一个,排除手机,手机只有一个属性色块,根本就不生成其他属性
    	            	$html .= self::generateOtherAttrInfo($i, $otherAttributeResult, $attrName, $productItemInfo);//生成默认的其他属性值  根据defaultitemid
	            	}
	            }
	            
	        }    	
        return $html;
    }
    
    /**
     * 生成其他属性信息根据defaultitemid 
     * $i当前是第几个属性(第一个属性除外)
     * $otherAttributeResult第一个属性外的其余属性信息
     * $attrName所有属性的属性名称(比如颜色重量等)
     * $productItemInfo当前product信息和次product下所有item信息
     */
    private function generateOtherAttrInfo($i, $otherAttributeResult, $attrName, $productItemInfo){
    	$html = "";
    	$defaultItemId = $productItemInfo['show_itemid'][0];
    	$attr = $otherAttributeResult["attr{$i}"];
        $attrTitle = $otherAttributeResult["attr{$i}Title"];
    	if( !empty($attr) && !empty($attrTitle) ){//存在属性的title(用来显示)和value(用来在JS中做值的比对)
    		$html .= " \n <div class='pro_color'>\n ";
            $html .= " \n <div class='p_row_7'> ".$attrName[$i-1]."</div>  \n ";//生成第二个属性的名称
            $html .= " \n <div class='p_row_8'> \n ";
            $html .= "\n <select id='".$i."' name='attributes' onchange='javascript:changeAttribute(this.value, this.id);'>";
            $html .= "\n <option value='-1'>".SELECTLABEL."</option>";
            foreach ($attr as $key => $item){//生成第二个属性值信息
                if( $productItemInfo["item_".$defaultItemId]["value_$i"] == $item ){
	                $html .= "\n <option value='".$item."' selected='selected'>". $attrTitle[$key] ."</option>";
	            }else{
	                $html .= "\n <option value='".$item."'>". $attrTitle[$key] ."</option>";
	            }
            }
	        $html .= "\n </select>";
	        $html .= "\n </div>";
	        $html .= "\n </div>";
    	}
    	return $html;
    }
    
    /**
     * $arrCategory 为当前产品上级所有category的url title集合
     */
    private function judgeIsMobile($arrCategory){//判断是否为手机，手机则不生成第二个下拉列表框
    	$isMobile = false;
    	$categoryId = $this->categoryId;//当前手机的category id
    	foreach ($arrCategory as $item) {//$arrCategory 是当前产品的所有category上级
            if(in_array($categoryId, $item)){
            	$isMobile = true;
            }
        }
    	return $isMobile;
    }
    
    /**
     * generate the price info
     * list price , sale price
     */
    private function generateItemPrice($marketPrice, $listPrice, $salePrice){
        $html = "<div class='pro_price'>";
        $html .= "<div><div class='p_row_1'>" . PRODUCTPAGEMARKETPRICE . "</div>
                 <div class='p_row_2'>" . UNIT."<span id='marketPrice'>".$marketPrice . "</span></div></div>";
    	if($listPrice != $salePrice){
//            $listPriceHtml = " \n <div id='productListPrice' >"
//                            ." \n <div id='productListPriceLabel' class='p_row_1'>".PRODUCTPAGEMIMIPRICE."</div>"
//                            ." \n <div class='p_row_2'><span id='productListPriceUnit'>".UNIT."</span>"
//                            ." \n <span id='productListPriceValue'>".$listPrice."</span>"
//                            ." \n </div></div>";
//            $salePriceHtml = " \n <div id='productSalePrice'>"
//                            ." \n <div id='productSalePriceLabel' class='p_row_1'>".PRODUCTPAGEPROMOTIONPRICE."</div>"
//                            ." \n <div class='p_row_4'><span id='productSalePriceUnit' style='color:#FF6600;font-family:微软雅黑;font-size:16px;font-weight:bold;'>".UNIT."</span>"
//                            ." \n <span id='productSalePriceValue' style='color:#FF6600;font-family:微软雅黑;font-size:16px;font-weight:bold;'>".$salePrice."</span>"
//                            ." \n </div></div>";
//            $listPriceHtml = " \n <div id='productListPrice' class='p_row_1'>"
//                            ." \n <span id='productListPriceLabel'>".PRODUCTPAGEMIMIPRICE."</span></div>"
//                            ." \n <div class='p_row_2'><span id='productListPriceUnit'>".UNIT."</span>"
//                            ." \n <span id='productListPriceValue'>".$listPrice."</span>"
//                            ." \n </div>";
//            $salePriceHtml = " \n <div id='productSalePrice' class='p_row_1'>"
//                            ." \n <span id='productSalePriceLabel'>".PRODUCTPAGEPROMOTIONPRICE."</span></div>"
//                            ." \n <div  class='p_row_4'><span id='productSalePriceUnit'>".UNIT."</span>"
//                            ." \n <span id='productSalePriceValue'>".$salePrice."</span></div>"
//                            ." \n </div>";
            $salePriceHtml = " \n <div id='productSalePrice' >"
                            ." \n <div id='productSalePriceLabel' class='p_row_1'>".PRODUCTPAGEPROMOTIONPRICE."</div>"
                            ." \n <div class='p_row_2'><span id='productSalePriceUnit' style='color:#FF6600;font-family:微软雅黑;font-size:16px;font-weight:bold;'>".UNIT
                            ."</span><span id='productSalePriceValue' style='color:#FF6600;font-family:微软雅黑;font-size:16px;font-weight:bold;'>".$salePrice."</span>"
                            ." \n </div></div>";
        }else{
//        	$listPriceHtml = " \n <div id='productListPrice' >"
//                            ." \n <div id='productListPriceLabel' class='p_row_1'>".PRODUCTPAGEMIMIPRICE."</div>"
//                            ." \n <div class='p_row_2'><span id='productListPriceUnit' style='color:#FF6600;font-family:微软雅黑;font-size:16px;font-weight:bold;'>".UNIT."</span>"
//                            ." \n <span id='productListPriceValue' style='color:#FF6600;font-family:微软雅黑;font-size:16px;font-weight:bold;'>".$listPrice."</span>"
//                            ." \n </div></div>";
            $salePriceHtml = " \n <div id='productSalePrice' >"
                            ." \n <div id='productSalePriceLabel' class='p_row_1'>".PRODUCTPAGEMIMIPRICE."</div>"
                            ." \n <div class='p_row_2'><span id='productSalePriceUnit' style='color:#FF6600;font-family:微软雅黑;font-size:16px;font-weight:bold;'>".UNIT
                            ."</span><span id='productSalePriceValue' style='color:#FF6600;font-family:微软雅黑;font-size:16px;font-weight:bold;'>".$salePrice."</span>"
                            ." \n </div></div>";
        }
//    	$html .= $listPriceHtml.$salePriceHtml;
    	$html .= $salePriceHtml;
    	$html .= "</div>";
    	return $html;
    }
    
    /**
     * generate the product metadata of main(is_primary==1)
     */
    private function generateMainMetadataHtml($metadata){
        $html = "";
    	if(!empty($metadata)){
        	$html .= "<div class='pro_parameter' style='height:auto;'>";
	        foreach ($metadata as $item) {
	        	$html .= "<div class='p_row_5' style='height:auto;'>" . $item["attribute"] . "</div>";
	        	$html .= "<div class='p_row_6' style='height:auto;'>" . $item["title"] . "</div>";
	        	$html .= "<div class='clear'></div>";
	        }
            $html .= "</div>";
        }
        return $html;
    } 
    
    /**
     * generate the all metadata info in details of the parameters tab Div
     */
    private function generateAllMetadataHtml($data, $productDesc){
        $html = "";
        if( !empty($data) ){
            foreach ($data as $item) {
            	$metadata = $item["metadatas"];
            	if( !empty($metadata) ){
            		//generate the metadata group title
	                $html .=  "<div class='depict_row_2'>";
	                $html .=  "   <ul>";
	                $html .=  "       <li class='style_3'>";
	                if( count($data) != 1 ){
	                    $html .=  $item["title"];
	                }
	                $html .=  "       </li>";
	                $html .=  "       <li class='style_2'>&nbsp;";
	                $html .=  "       </li>";
	                $html .=  "   </ul>";
	                $html .=  "</div>";
	                //0107开始重新构造数据用来处理多选情况
	                $metadataTempe = array();
	                $tempAttribute = "";
	                $tempTitle = "";
	                $tempi = "";
	                $i = 0;
	                foreach ($metadata as $itemData) {
	                	if( $tempAttribute != trim($itemData["attribute"]) ){
	                		$metadataTempe[$i]["attribute"] = $itemData["attribute"];
                            $metadataTempe[$i]["title"] = $itemData["title"];
	                        $tempAttribute = trim($itemData["attribute"]);
	                        $tempi = $i;
	                        $i++;
	                	}else{
                            if ($metadataTempe[$tempi]["title"][0] == '[')
                            {
                                $metadataTempe[$tempi]["title"] .= "&nbsp;&nbsp;[".$itemData["title"]."]";
                            }
                            else
                            {
                                $metadataTempe[$tempi]["title"] = 
                                    "[".$metadataTempe[$tempi]["title"]."]&nbsp;&nbsp;"."[".$itemData["title"]."]";
                            }
                            //$metadataTempe[$tempi]["title"] .= "&nbsp;&nbsp;&nbsp;&nbsp;".$itemData["title"];
	                	}
	                }
	                //0107结束
	                //generate the metadata info
//	                foreach ($metadata as $itemData) {
	                foreach ($metadataTempe as $itemData) {//调用新数据
	                    $html .= "<div class='depict_row_2'>";
	                    $html .= "  <ul>";
	                    $html .= "      <li class='style_1'>";
	                    $html .= $itemData["attribute"];
	                    $html .= "     </li>";
	                    $html .= "     <li class='style_2'>";
	                    $html .= trim($itemData["title"]);
	                    $html .= "     </li>";
	                    $html .= "  </ul>";
	                    $html .= "</div>";
	                }
	                
            	}
            }
        }
//    	if(!empty($productDesc)){
//	    	$html .= "<div class='depict_row_2' style='height:auto;'><ul><li class='style_3' style='height:auto;'>产品描述</li>";
//	    	$html .= "<li class='style_2' style='height:auto;'>$productDesc</li></ul></div>";
//    	}
    	return $html;
    }
    
    private function promptInfo(){
    	$html = 
<<<str_result

    	<!-- prompt info div -->
    <div id="checkcurrent" style="display: none; border: 2px solid  #76A73A;          padding: 5px;  left: 40%; top: 50%; position: absolute; z-index: 9999; width: 350px; height: auto; background-color: rgb(255, 255, 255); font-size: 12px; text-align: center;">
        <div style="font-size:16px; margin-top: 15px; margin-bottom: 10px; text-align: center; margin-left: 5px;color:#007AD2;">您好，您所选择的这件商品不能添加到购物车</div>
        <div id="currentinfo" style="margin-bottom: 10px; text-align: left; margin-left: 5px;"> 
        
        </div>
        <div style="margin: 0pt auto; bottom: 3px; left: 40%; color: rgb(255, 0, 0); font-weight: bold; cursor: pointer;">
            <span onClick="javascript:ProductContent.closePromptInfo();">[关闭]</span>
        </div>
       
    </div>
    
    <div id="addWishlistDiv" style="display: none; border: 2px solid  #76A73A;          padding: 5px;  left: 40%; top: 50%; position: absolute; z-index: 9999; width: 350px; height: auto; background-color: rgb(255, 255, 255); font-size: 12px; text-align: center;">
        <div style="font-size:16px; margin-top: 15px; margin-bottom: 10px; text-align: center; margin-left: 5px;color:#007AD2;">您好，您所选择的商品已经添加到收藏夹</div>
        <div style="margin: 0pt auto; bottom: 3px; left: 40%; color: rgb(255, 0, 0); font-weight: bold; cursor: pointer;">
            <span onClick="javascript:ProductContent.closePromptInfoDiv('addWishlistDiv');">[关闭]</span>
        </div>
       
    </div>
    
    <!-- prompt info div -->
    
    <!-- continue Select info -->
    
    <div id="continueSelect" style="display: none; border: 2px solid  #76A73A;padding: 5px;  left: 40%; top: 50%; position: absolute; z-index: 9999; width: 350px; height: auto; background-color: rgb(255, 255, 255); font-size: 12px; text-align: center;">
        <div style="font-size:16px; margin-top: 15px; margin-bottom: 10px; text-align: center; margin-left: 5px;color:#007AD2;">请继续选择产品属性</div>
        <div style="margin: 0pt auto; bottom: 3px; left: 40%; color: rgb(255, 0, 0); font-weight: bold; cursor: pointer;">
            <span onClick="javascript:ProductContent.closeContinueSelectInfo();">[关闭]</span>
        </div>
       
    </div>
    
    <!-- continue Select info -->
    
str_result;
    
        return $html;
    }
    
   
	
}


